#!/usr/bin/env python3
import random
import socket
import sys

from scapy.all import IP, TCP, Ether, get_if_hwaddr, get_if_list, sendp

def main():
    if len(sys.argv)<3:
        print('pass 2 arguments: <destination> "<message>"')
        exit(1)

    # 直接使用命令行参数，不进行DNS解析
    addr = sys.argv[1]

    # 在命名空间中使用固定的接口名
    iface = "eth0"

    print("sending on interface %s to %s" % (iface, str(addr)))

    # 使用正确的MAC地址
    src_mac = "08:00:00:00:01:01"  # h1的正确MAC地址
    dst_mac = "08:00:00:00:01:00"  # s1的MAC地址

    pkt = Ether(src=src_mac, dst=dst_mac)
    pkt = pkt /IP(dst=addr, src="10.0.1.1") / TCP(dport=1234, sport=random.randint(49152,65535)) / sys.argv[2]
    pkt.show2()
    sendp(pkt, iface=iface, verbose=False)

if __name__ == '__main__':
    main()
